﻿Shader "RMap"
{
    Properties
    {
        _BaseColor("Color",Color) = (1,1,1,1)
        _BaseMap("RMap",2D) = "white"{}
    }
    SubShader
    {
        Tags
        {
            "RenderPipeline"="UniversalRenderPipeline"
            "LightMode"="UniversalForward"
            "RenderType"="Opaque"
        }
        LOD 100

        HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

        TEXTURE2D(_BaseMap);    SAMPLER(sampler_BaseMap);

        CBUFFER_START(UnityPerMaterial)
        half4 _BaseColor;
        CBUFFER_END
        ENDHLSL

        pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            struct a2v
            {
                float4 positionOS : POSITION;
                float3 normalOS : NORMAL;
                float2 texcoord : TEXCOORD;
            };

            struct v2f
            {
                float4 positionCS : SV_POSITION;
                half3 normalWS : TEXCOORD0;
                half2 texcoord : TEXCOORD1;
            };

            v2f vert(a2v v)
            {
                v2f o;
                o.positionCS = TransformObjectToHClip(v.positionOS.xyz);
                o.normalWS = TransformObjectToWorldNormal(v.normalOS); 
                o.texcoord = v.texcoord;
                return o;
            }

            half4 frag(v2f i):SV_Target
            {
                Light light = GetMainLight();
                half3 normalWS = normalize(i.normalWS); 

                half halfLambert = saturate(dot(light.direction, normalWS) * 0.5 + 0.5);
                half3 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, half2(halfLambert,0.5)).rgb * _BaseColor.rgb;
                return half4(albedo, 1);
            }
            ENDHLSL
        }
    }
}